import {FCTable} from "@components";
import React, { useEffect, useState } from 'react';

import { DetailsModelBodyHeight } from "../config";

import { findEmerMsgDetails } from '@apis/massMsgApi'

const columns = [
  { title: '姓名', dataIndex: 'custName', key: 'custName', open: true },
  { title: '电话', dataIndex: 'phoneNo', key: 'phoneNo', open: true },
  // { title: '邮箱', dataIndex: 'email', key: 'email', open: true },
  { title: '保单号', dataIndex: 'policyNo', key: 'policyNo', open: true },
];

const DetailsTable = ({height, msgCustMainId}) => {
  const [loading, setLoading] = useState(false);
  const [dataSource, setDataSource] = useState([])
  const [pagiProps, setPagiProps] = useState({ current: 1, pageSize: 20 })

  const getDataSource = async (pageProps) => {
    setLoading(true);
    const {pageSize, current: currentPage} = pageProps
    const { data, error } = await findEmerMsgDetails({queryDto: { msgCustMainId }, currentPage, pageSize});
    setLoading(false);

    if (error) return; setDataSource([]);
    setPagiProps({ ...pagiProps, current: data.currentPage, total: data.totalCount, pageSize:data.pageSize });
    setDataSource(data.pageList);
  };

  const onTableChange = ({ pagination }) => {
    getDataSource(pagination)
  };

    const tableProps = {
      // 自适应高度
      scroll: { // ModelBody高度 - ModelBody上padding - info高度 - Descriptions title高度 - 表头高度 - 分页器高度
        y: DetailsModelBodyHeight - 24 - height - 42 - 55 - 64
      },
      columns,
      rowKey: 'msgCustomerId',
      loading,
      dataSource,
      pagination: pagiProps,
      onTableChange,
    }

    useEffect(() => {
      getDataSource(pagiProps);
    },[])

    return (
      <FCTable {...tableProps}  />
    )
};
export default DetailsTable;